< previous page page_117 next page >

Page 117
The font used to draw the word styles in Figure 4.2 is MS Sans Serif. It does not scale well, and it gives poor results at many font sizes.
TrueType fonts are designed to be scaled so that they produce good results at most sizes. TrueType fonts that are present on most Windows systems include Arial, Courier New, and Times New Roman.
The section "CreateFont Function" later in this chapter explains how the font mapper selects fonts and gives further insights into using fonts at different scales.
Text Metrics
If you look very closely at Figure 4.2, you will see that the words' baselines (the line where the characters sit) do not all line up exactly. On the last line, for example, the baseline of the word "colors" is slightly above the baseline of the word "different." As it draws text using different fonts, program Styles uses its current font size to align the bottom of the text. Unfortunately, not all fonts position their baselines the same distance from the bottom of the font.
Figure 4.3 shows some important features of a character's geometry. Each character occupies a certain area called its cell. Internal leading is the space at the top of the cell. Usually the internal leading space is empty, though certain special features such as accent marks may occupy this space.
The character's ascent is the distance from the top of the character's cell to the font's baseline. The character's descent is the distance from the font's baseline to the bottom of the character cell. The font's height is the sum of its ascent and its descent.
The GetTextMetrics API function returns several useful pieces of information about a font, including its internal leading, ascent, descent, and height values. This function takes as its first parameter the handle of a device context for which it should retrieve information. For example, if this is the device context handle of a form, GetTextMetrics returns information about the font currently selected by the form.
The GetTextMetrics function's second parameter is a TEXTMETRIC data structure. The function fills this structure with information about the font.
z0137-01.gif
Figure 4.3
Anatomy of a character.

 
< previous page page_117 next page >